﻿using UnityEngine;
using System.Collections;

public class BossListTabBar : MonoBehaviour
{
	BossListTabBarButton[] m_tabBarButton;
	
	int m_selectedIndex = 0;
	public int SelectedIndex
	{
		get { return m_selectedIndex; }
		set { if (m_selectedIndex == value) return; m_selectedIndex = value; }
	}

	public void Init()
	{
		m_tabBarButton = transform.GetComponentsInChildren<BossListTabBarButton>();
		for (int i = 0; i < m_tabBarButton.Length; i++)
		{
			m_tabBarButton[i].ButtonIndex = i;
			m_tabBarButton[i].TabBar = this;
		}
		
		if (m_tabBarButton.Length > 0)
		{
			m_tabBarButton[m_selectedIndex].IsChecked = true;
		}
	}
	
	public void SelectTab(int buttonIndex)
	{
		if (m_selectedIndex == buttonIndex)
			return;
		
		m_selectedIndex = buttonIndex;
		
		for (int i = 0; i < m_tabBarButton.Length; i++)
		{
			if (m_selectedIndex == m_tabBarButton[i].ButtonIndex)
			{
				m_tabBarButton[i].IsChecked = true;
			}
			else
			{
				m_tabBarButton[i].IsChecked = false;
			}
		}
	}
}
